package com.lemobar.pay.model.notify;

import com.lemobar.pay.model.BaseWxPayResult;
import com.lemobar.pay.utils.converter.PayOrderNotifyResultConverter;
import com.lemobar.pay.utils.xml.XStreamInitializer;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author Selier
 */
@Data
@XStreamAlias("xml")
public class PayOrderNotifyResult extends BaseWxPayResult implements Serializable {
    private static final long serialVersionUID = 5389718115223345496L;
    @XStreamAlias("promotion_detail")
    private String promotionDetail;
    @XStreamAlias("device_info")
    private String deviceInfo;
    @XStreamAlias("openid")
    private String openid;
    @XStreamAlias("is_subscribe")
    private String isSubscribe;
    @XStreamAlias("sub_openid")
    private String subOpenid;
    @XStreamAlias("sub_is_subscribe")
    private String subIsSubscribe;
    @XStreamAlias("trade_type")
    private String tradeType;
    @XStreamAlias("bank_type")
    private String bankType;
    @XStreamAlias("total_fee")
    private Integer totalFee;
    @XStreamAlias("settlement_total_fee")
    private Integer settlementTotalFee;
    @XStreamAlias("fee_type")
    private String feeType;
    @XStreamAlias("cash_fee")
    private Integer cashFee;
    @XStreamAlias("cash_fee_type")
    private String cashFeeType;
    @XStreamAlias("coupon_fee")
    private Integer couponFee;
    @XStreamAlias("coupon_count")
    private Integer couponCount;
    private List<WxPayOrderNotifyCoupon> couponList;
    @XStreamAlias("transaction_id")
    private String transactionId;
    @XStreamAlias("out_trade_no")
    private String outTradeNo;
    @XStreamAlias("attach")
    private String attach;
    @XStreamAlias("time_end")
    private String timeEnd;
    @XStreamAlias("version")
    private String version;
    @XStreamAlias("rate_value")
    private String rateValue;
    @XStreamAlias("sign_type")
    private String signType;

    public static PayOrderNotifyResult fromXML(String xmlData) {
        XStream xstream = XStreamInitializer.getInstance();
        xstream.processAnnotations(PayOrderNotifyResult.class);
        xstream.registerConverter(new PayOrderNotifyResultConverter(xstream.getMapper(), xstream.getReflectionProvider()));
        PayOrderNotifyResult result = (PayOrderNotifyResult) xstream.fromXML(xmlData);
        result.setXmlString(xmlData);
        return result;
    }

}
